﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="Organisation", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(Organisation))]
    public class OrganisationSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IOrganisation clazz;
        
        public OrganisationSerializer(IOrganisation clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("RegistryCode");
            if (clazz.RegistryCode!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.RegistryCode.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : RegistryCode");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("Name");
            if (clazz.Name!=null) {
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.Name.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Name");
            }
            Writer.WriteEndElement();
            if (clazz.PersonalIDCode!=null) {
                Writer.WriteStartElement("PersonalIDCode");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "NonEmptyString");
                Writer.WriteString(clazz.PersonalIDCode.ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Type!=null) {
                Writer.WriteStartElement("Type");
                Writer.WriteTypeAttribute("http://producers.kis.xtee.riik.ee/producer/kis", "OrganisationType");
                Writer.WriteString(clazz.Type.ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "RegistryCode")) {
                goto RegistryCode;
            }
            else {
                if ((Reader.LocalName == "Name")) {
                    goto Name;
                }
                else {
                    if ((Reader.LocalName == "PersonalIDCode")) {
                        goto PersonalIDCode;
                    }
                    else {
                        if ((Reader.LocalName == "Type")) {
                            goto Type;
                        }
                        else {
                            return;
                        }
                    }
                }
            }
        RegistryCode:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Organisation>RegistryCode");
            }
            clazz.RegistryCode = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("RegistryCode"));
            goto START;
        Name:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Organisation>Name");
            }
            clazz.Name = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("Name"));
            goto START;
        PersonalIDCode:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Organisation>PersonalIDCode");
            }
            clazz.PersonalIDCode = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.NonEmptyString(Reader.ReadElementString("PersonalIDCode"));
            goto START;
        Type:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>Organisation>Type");
            }
            clazz.Type = new global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.OrganisationType(Reader.ReadElementString("Type"));
            goto START;
        }
    }
}
